package com.luffyzhao.demo.configuration;

import com.luffyzhao.demo.properties.ApplicationProperties;
import com.surftools.BeanstalkClient.Client;
import com.surftools.BeanstalkClientImpl.ClientImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanstalkConfiguration {
    @Bean(destroyMethod = "close")
    public Client factory(ApplicationProperties properties) {
        Client client = new ClientImpl(properties.getHost(), properties.getPort());
        client.useTube(properties.getProducerTube());
        client.watch(properties.getConsumerTube());
        client.ignore("default");

        return client;
    }

}
